package edu.zhuoxun.blogserver.entity;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.Data;

import java.util.List;

@Data
public class Page<T> {
    public Page(QueryWrapper<T> wrapper, BaseMapper<T> mapper, int page, int size) {
        Long count = mapper.selectCount(wrapper);
        setTotal(count.intValue());
        setTotalPage((int) Math.ceil(count * 1.0 / size));
        setPage(page);
        setList(mapper.selectList(wrapper.last(" limit " + ((page - 1) * size) + "," + size)));
    }

    private List<T> list;
    private int page;
    private int total;
    private int totalPage;
}
